<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
<?php 
$layout = explode('&&&', file_get_contents('layout.html'));
echo $layout[0];

session_start();
if (!(isset($_SESSION['username'])))
	header("location:login.php");
?>

<html>
<head>

</head>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<body>

<!-- Begin Main Column -->

<div id="mainContent">
	
  <h2>Edit Event</h2>

<!-- Begin Side Column -->
<!-- Begin Footer -->

	<?php
		$workshop_id=$_GET['id'];
		
		ob_start();
		$host="localhost"; // Host name
		$username="root"; // Mysql username
		$password=""; // Mysql password
		$db_name="rtl"; // Database name
			
		// Connect to server and select databse.
		mysql_connect("$host", "$username", "$password")or die("cannot connect");
		mysql_select_db("$db_name")or die("cannot select DB");
		
		$workshop_by_id = mysql_query("SELECT * FROM WORKSHOP WHERE WRKSPID='$workshop_id'") or die (mysql_error());
		$row=mysql_fetch_array($workshop_by_id);
		
		//Get the workshop topic name
		$workshop_topic = $row['WRKSPTOPICID'];
		$workshop_by_topic=mysql_query("SELECT WRKSPTOPIC FROM WORKSHOPTOPICS WHERE WRKSPTOPICID='$workshop_topic'") or die (mysql_error());
		$workshop_topic = mysql_result($workshop_by_topic,0);
		
		//Get the workshop id
		$workshop_id= $row['WRKSPID'];
		
		//Get the workshop language
		$workshop_lang_id = $row['WRKSPLANGID'];
		$lang_name=mysql_query("SELECT LANG FROM LANGUAGE WHERE LANGID='$workshop_lang_id'") or die (mysql_error());
		$workshop_lang=mysql_result($lang_name,0);
		
		//Get the organization
		$workshop_org_id = $row['ORGID'];
		$org_name=mysql_query("SELECT ORGNAME FROM ORGANIZATION WHERE ORGID='$workshop_org_id'") or die (mysql_error());
		$workshop_org=mysql_result($org_name,0);
		
		//Get the workshop Presenter
		$workshop_pres_id = $row['PRESENTERID'];
		$pres_name=mysql_query("SELECT * FROM PRESENTER WHERE PRESENTERID='$workshop_pres_id'") or die (mysql_error());
		$pres_row=mysql_fetch_array($pres_name);
		
		//Get Participants for this workshop
		$participants=mysql_query("SELECT * FROM WORKSHOPPARTICIPANTS WHERE WRKSPID='$workshop_id'") or die (mysql_error());
		
		//Echo workshop info
		echo "<h3>"."<p></p>"."Workshop Information "."<a href=\"EditWorkshop.php?id=$workshop_id&event=1\">"."["."Edit"."]"."</a>"."<p>"."</h3>";
		
		echo "Workshop ID: ". $row['WRKSPID']."<br>";
		echo "Topic: ". $workshop_topic."<br>";
		echo "Language: ". $workshop_lang."<br>";
		echo "Organization: ".$workshop_org."<br>";
		echo "Date: ".$row['WRKSPDATE']."<br>";
		echo "Time: ".$row['WRKSPTIME']."<br>";
		echo "Location: ".$row['LOCATION']."<br>";
		echo "Address: ".$row['ADDRESS']."<br>";
		echo "City: ".$row['CITY']."<br>";
		echo "Zipcode: ".$row['ZIPCODE']."<br>";
		echo "Children Present: ".$row['CHILDRENPRESENT']."<br>";
		
		//Presenter Info
		$no_of_presenters=mysql_num_rows($pres_name);
		echo "<h3><p></p>Presenter Information "; if($no_of_presenters != 0) {$pres_id=$pres_row['PRESENTERID']; echo "<a href=\"EditPresenter.php?pid=$pres_id&id=$workshop_id\">[Edit]</a>";} else if($no_of_presenters==0){echo "<a href=\"CreatePresenter.php?id=$workshop_id\">[Add]</a>";} echo "<p></h3>";
		
		if($no_of_presenters==0) {
			echo "No presenters exist for this event<br>";
		}
		
		else if($no_of_presenters==1) {
			//Get Presenter organization
			$pres_org_id = $pres_row['ORGID'];
			$pres_org_name=mysql_query("SELECT ORGNAME FROM ORGANIZATION WHERE ORGID='$pres_org_id'") or die (mysql_error());
			$pres_org=mysql_result($pres_org_name,0);
			
			echo "Presenter ID: ".$pres_row['PRESENTERID']."<br>";
			echo "Organization: ".$pres_org."<br>";
			echo "First Name: ".$pres_row['FIRSTNAME']."<br>";
			echo "Last Name: ".$pres_row['LASTNAME']."<br>";
			echo "Address: ".$pres_row['ADDRESS']."<br>";
			echo "City: ".$pres_row['CITY']."<br>";	
			echo "Zipcode: ".$pres_row['ZIPCODE']."<br>";
			echo "Phone Number: ".$pres_row['PHONENO']."<br>";
			echo "Email: ".$pres_row['EMAIL']."<br>";
			echo "Fax Number: ".$pres_row['FAX_NO']."<br>";	
			echo "Contract Trainer: ".$pres_row['CONTRACTTRAINER']."<br>";	
			
		}
		
		//Participant Info
		$no_of_participants=mysql_num_rows($participants);
		echo "<h3>"."<p></p>"."Participant Information "."<a href=\"CreateParticipant.php?id=$workshop_id\">"."["."Add"."]"."</a>"."<p>"."</h3>";
		
		if($no_of_participants==0) {
			echo "No participants exist for this event<br>";  
		}
		else {
    			echo "<table border='1'>";
  				echo "<tr> <th>ID</th> <th>Name</th> <th>Address</th> <th>City</th><th>Zipcode</th><th>Phone Number</th>";
  				//keeps getting the next row until there are no more to get
				
				while($row = mysql_fetch_array($participants))
				{
					// Print out the contents of each row into a table
					$part_id = $row['PARTICIPANTID'];
					$no_children_query = mysql_query("SELECT NUMBEROFCHILDREN FROM WORKSHOPPARTICIPANTS WHERE WRKSPID='$workshop_id' AND PARTICIPANTID='$part_id'");
					$no_children = mysql_result($no_children_query,0);
					$total_no_children = $total_no_children + $no_children;
					$participant=mysql_query("SELECT * from PARTICIPANTS WHERE PARTICIPANTID='$part_id'");
					$part_row=mysql_fetch_array($participant);
					$participant_id=$part_row['PARTICIPANTID'];
					echo "<tr><td>";
					echo $participant_id;
					echo "</td><td>";
					echo "<a href=\"EditParticipant.php?id=$participant_id&event=1&wid=$workshop_id\">".$part_row['FIRSTNAME']." ".$part_row['LASTNAME']."</a>";
					echo "</td><td>";
					echo $part_row['ADDRESS'];
					echo "</td><td>";
					echo $part_row['CITY'];
					echo "</td><td>";
					echo $part_row['ZIPCODE'];
					echo "</td><td>";
					echo $part_row['PHONENO'];					
				}
				
				echo "</table><br>";
				echo "# of Participants: $no_of_participants<br>";
				echo "# of Children: $total_no_children";	
		}
	?>
    </div>
    
<?php
echo $layout[1];
?>
</body>
</html>
